package projectAnalysis.advancedTechAnalyzer;

import java.util.*;

public class TechFuzzyClassifier {
    // 常见技术的groupId前缀映射（可扩展）
    private static final Map<String, String> GROUP_ID_MAPPING = new HashMap<>();
    static {
        // 框架类
        GROUP_ID_MAPPING.put("org.springframework", "Spring 生态");
        GROUP_ID_MAPPING.put("org.mybatis", "MyBatis 生态");
        GROUP_ID_MAPPING.put("com.baomidou", "MyBatis-Plus");
        GROUP_ID_MAPPING.put("io.springfox", "Swagger");
        // 数据库类
        GROUP_ID_MAPPING.put("mysql", "MySQL 驱动");
        GROUP_ID_MAPPING.put("com.oracle", "Oracle 驱动");
        GROUP_ID_MAPPING.put("org.postgresql", "PostgreSQL 驱动");
        // 中间件类
        GROUP_ID_MAPPING.put("redis.clients", "Jedis/Redis");
        GROUP_ID_MAPPING.put("com.rabbitmq", "RabbitMQ");
        GROUP_ID_MAPPING.put("org.apache.kafka", "Kafka");
        // 工具类
        GROUP_ID_MAPPING.put("org.projectlombok", "Lombok");
        GROUP_ID_MAPPING.put("ch.qos.logback", "Logback");
    }

    // 对未匹配到特征的依赖进行模糊分类
    public static Map<String, List<String>> classifyUnmatchedDependencies(List<String> rawDependencies) {
        Map<String, List<String>> result = new HashMap<>();
        for (String dep : rawDependencies) {
            String groupId = dep.split(":")[0];
            String artifactId = dep.split(":")[1];
            String techName = "未知技术";
            
            // 优先匹配groupId前缀
            for (Map.Entry<String, String> entry : GROUP_ID_MAPPING.entrySet()) {
                if (groupId.startsWith(entry.getKey())) {
                    techName = entry.getValue();
                    break;
                }
            }
            
            // 分组存储（技术名称 → 依赖列表）
            result.computeIfAbsent(techName, k -> new ArrayList<>()).add(artifactId);
        }
        return result;
    }
}